package org.example;

import org.example.config.AppConfig;
import org.example.properties.AppProperties;
import org.example.properties.JdbcProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

public class T {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Test
    public void test() {
        System.out.println("abc123...");
        logger.debug("info 123 ...");
        logger.info("info 123 ...");
        logger.warn("info 123 ...");
        logger.error("info 123 ...");
    }

    @Test
    public void testPropertiesLoaderUtils() {
        try {
            Properties app = PropertiesLoaderUtils.loadProperties(new ClassPathResource("app.properties"));
            String appName = app.getProperty("appName");
            System.out.println(appName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void testAppProperties() {
        System.out.println(AppProperties.appName);
        System.out.println(AppProperties.jdbcUrl);
    }

    @Test
    public void testJdbcProperties() {
        System.out.println(JdbcProperties.url);
        System.out.println(JdbcProperties.driver);
        System.out.println(JdbcProperties.username);
        System.out.println(JdbcProperties.password);
    }

    private AbstractXmlApplicationContext app;
    @Before
    public void before() {
        app = new ClassPathXmlApplicationContext("classpath:spring/spring-context.xml");
    }
    @After
    public void after() {
        app.close();
    }
}
